package base;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class SumProg {
    
	public int binarySearch(int[] sorted, int first, int upto, int key) {
	    
	    while (first < upto) {
	        int mid = (first + upto) / 2;  // Compute mid point.
	        if (key < sorted[mid]) {
	            upto = mid;     // repeat search in bottom half.
	        } else if (key > sorted[mid]) {
	            first = mid + 1;  // Repeat search in top half.
	        } else {
	            return mid;     // Found it. return position
	        }
	    }
	    return -(first + 1);    // Failed to find key
	}
	
	public static void leftShift(int[] array, int n) {
	    for (int shift = 0; shift < n; shift++) {
	        int first = array[0];
	        System.arraycopy( array, 1, array, 0, array.length - 1 );
	        array[array.length - 1] = first;
	    }
	}
	
	public static void main(String[] args) {
       /*int[] arr = {0,1,2,3,5,6,7,11,12,14,19,20};
       int given = 6;
       SumProg prog = new SumProg();
       System.out.println("Index is "+prog.binarySearch(arr, 0, arr.length, given));*/
		
		/*int[] arr = {1,1,2,2,3,3,4,4,4,5,5,5,6,6,7,7,8,8,8,8,9,9,10,10};
		Set<Integer> intset = new HashSet<Integer>();
		for(int i=0;i<arr.length;i++){
			if(intset.contains(arr[i])){
				intset.remove(arr[i]);
			}else{
				intset.add(arr[i]);
			}
		}
		
		Iterator<Integer> itr = intset.iterator();
		while(itr.hasNext()){
			System.out.println(itr.next().toString());
		}*/
		
		int[] array = {1,2,3,4,5,6,7,8};
	    leftShift( array, 4);
	    System.out.println( Arrays.toString( array));
	    
	    try{
	    	System.out.println("hello");
	    	//System.exit(0);
	    	//throw new IllegalArgumentException();
	    }catch(Exception e){
	    	System.out.println("exception");
	    }finally{
	    	System.out.println("finally");
	    }
       
	}

}
